package com.android.sms_manager;

import java.util.List;
import java.util.Map;

import com.android.sms_manager.data.MyData;
import com.android.sms_manager.service.QueryService;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ListDraftActivity extends Activity{

	private List<Map<String,Object>>data = null;
	private String title = null;
	private String uri = null;
	private int protocol;
	private ListView smsList = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		title = this.getString(R.string.draft);
		protocol = MyData.PROTOCOL_SMS;
		uri = MyData.URI_SMS_DRAFT;
		
		this.setTitle(title);
		this.setContentView(R.layout.draft);
		
		smsList = (ListView)this.findViewById(R.id.draftlist);
		loadData();
	}
	
	private void loadData(){
		String from[] = null;
		
		data = QueryService.getConversation(this, uri, protocol,null);
		
		from = new String[]{
				MyData.KEY_DATE,
				MyData.KEY_BODY,
				MyData.KEY_ID};
		
		SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.smsitem,
				from, new int[]{
						R.id.smsdate,
						R.id.smsbody});
		
		if(data !=null && !data.isEmpty())
			smsList.setAdapter(adapter);
	}
}
